#include <STC15F2K60S2.H>
#include <intrins.h>
sbit TX = P1^0;
sbit RX = P1^1;



void Delay12us()		//@12.000MHz
{
	unsigned char i;

	_nop_();
	_nop_();
	i = 38;
	while (--i);
}


void ultr_int()
{
    uchar i;
    for(i= 0;i<8;i++)
    {
    TX = 1;
    Delay12us();
    TX = 0;
    Delay12us();
    }
}



uint ultr_read()
{   
    uint csb =0;
    CMOD = 0;
    CH = CL = 0;
    EA = 0;
	ultr_int();
    EA = 1;
	
    CR = 1;
    while((RX == 1) &&(CF == 0));
    CR =0;
    if(CF == 0)
    {
        csb = (CH<<8 )|CL;
        return (csb *0.017);
    }else{
        CF = 0;
        return 0;
    }
    



}